cap program drop iv_ctrls_simple

program define iv_ctrls_simple

syntax varlist, indvar(varlist) iv(varlist) title(string)

	foreach depvar in `varlist' {

		local title `title'
		local label: var label `depvar' 
		local iv_label: var label `iv' 
			
		xtreg `indvar' `iv' $ictrls_3l_varying, fe
			local F_stat_round_ctrls = round(e(F),.001)	

		xtivreg `depvar' (`indvar' = `iv') $ictrls_3l_varying , fe
			eststo ucdp_all_ctrls
				estadd local FE "Yes"
				estadd local time "N/A"
				estadd local ctrls "Yes"
				estadd local IV "`iv_label'"
				estadd local F_stat "`F_stat_round_ctrls'"		
						
		esttab ucdp_all_ctrls using "output/`title'.tex", replace ///
			label booktabs b(3) se(3) eqlabels(none) br ///
			mgroups("`label'", pattern(1 0 0 0 0 0 0 0 0 0) ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
			nomtitles ///
			star(* 0.10 ** 0.05 *** 0.01) nonotes scalars("ctrls Controls" "FE Country FE" "time Years of peace" "IV IV" "F_stat First stage F") 
	
		}
	
end
		
	
